package com.hmsg.health.qiniu;

//public class QiniuUpload {
//}


import com.qiniu.common.Zone;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import org.springframework.stereotype.Service;

@Service
public class QiniuUpload {
    // 设置好账号的ACCESS_KEY和SECRET_KEY
    final String ACCESS_KEY = "XKOKACjcZ0XXFoM-Itu-D2z60edkSEh_yd0yReJd";
    final String SECRET_KEY = "9Ih7lgbjl8TG5hOypAG0zDGN40-zq8fQvFF8oUkC";

    // 要上传的空间
    public static final String BUCKET_MIANAO_IMG = "mianao-image";
    public static final String HOST_MIANAO_IMG = "http://test.images9.hmsgtech.com/";

    public static final String BUCKET_CLIENT_IMG = "client-image";
    public static final String HOST_CLIENT_IMG = "http://test.images6.hmsgtech.com/";

    public static final String BUCKET_STUDIO_IMG = "studio-imgs";

    public static final String BUCKET_MIANAO_MEDIA = "mianao-media";
    public static final String HOST_MIANAO_MEDIA = "http://test.images2.hmsgtech.com/";

    // 密钥配置
    Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);

    // 第二种方式: 自动识别要上传的空间(bucket)的存储区域是华东、华北、华南。
    Zone z = Zone.autoZone();
    Configuration c = new Configuration(z);

    // 创建上传对象
    UploadManager uploadManager = new UploadManager(c);

    // 简单上传，使用默认策略，只需要设置上传的空间名就可以了
    public String getClientImgToken() {
        return auth.uploadToken(BUCKET_CLIENT_IMG);
    }

    public String getMianaoImgToken() {
        return auth.uploadToken(BUCKET_MIANAO_IMG);
    }

    public String getMianaoMediaToken() {
        return auth.uploadToken(BUCKET_MIANAO_MEDIA);
    }

    public static String getMianaoImageUrl(String saveKey) {
        return QiniuUpload.HOST_MIANAO_IMG + saveKey;
    }

}
